import request from "@/utils/request";

enum API {
  // 获取全部已有用户信息
  ALLUSER_URL = "/admin/acl/user/",
  // 新增用户
  ADDUSER_URL = "/admin/acl/user/save",
  // 修改用户
  UPDATEUSER_URL = "/admin/acl/user/update",
  // 删除用户
  DELETEUSER_URL = "/admin/acl/user/remove/",
  // 批量删除用户接口
  DELETEALLUSER_URL = "/admin/acl/user/batchRemove",
  // 获取职位
  GETROLE_URL = "/admin/acl/user/toAssign/",
  // 分配角色
  ASSIGNROLE_URL = "/admin/acl/user/doAssignRole",
}

// 获取用户信息接口
export const reqUserInfo = (page: number, limit: number, username: string) =>
  request.get<any, any>(
    API.ALLUSER_URL + `${page}/${limit}?username=${username}`
  );
// 新增用户或修改用户接口
export const reqAddOrUpdateUser = (data: any) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEUSER_URL, data);
  } else {
    return request.post<any, any>(API.ADDUSER_URL, data);
  }
};
// 获取职位
export const reqAllRole = (userId: number) =>
  request.get<any, any>(API.GETROLE_URL + userId);
// 分配角色
export const reqAssignRole = (data: any) =>
  request.post<any, any>(API.ASSIGNROLE_URL, data);
// 删除用户
export const reqDeleteUser = (userId: number) =>
  request.delete<any, any>(API.DELETEUSER_URL + userId);
// 批量删除用户
export const reqAllDeleteUser = (idList: any) =>
  request.delete<any, any>(API.DELETEALLUSER_URL, idList);
